package rita.grammar;

import java.util.ArrayList;
import java.util.List;

import codeblocks.Block;
import codeblocks.BlockConnector;

import renderable.RenderableBlock;
import rita.grammar.exception.IncompleteSentenceException;
/**
 * Esta clase representa a un bloque que equivale a la sentencia "return" de java
 * 
 * @author Vanessa Aybar Rosales
 * */
public class ReturnBlock extends Command {

	@Override
	public List<StringBuffer> render(RenderableBlock rBlock)
			throws IncompleteSentenceException {
		StringBuffer sb1 = new StringBuffer("return ");
		StringBuffer sb2 = new StringBuffer(";");
		List<StringBuffer> returnedRenderList = new ArrayList<StringBuffer>();
		List<StringBuffer> fromParser = new ArrayList<StringBuffer>();
		BlockConnector bc = rBlock.getBlock().getSocketAt(0);
		if (bc.hasBlock()) {
			fromParser.addAll(JavaCodeGenerator.generateCode(RenderableBlock
					.getRenderableBlock(bc.getBlockID())));
		}
		
		returnedRenderList.add(sb1);
		returnedRenderList.addAll(fromParser);
		returnedRenderList.add(sb2);
		return returnedRenderList;
	}

}
